<template>
	<view :class="Visible ? 'product-popup open' : 'product-popup close'" @touchmove.stop.prevent="" @click="closePopup">
		<view class="popup-bg"></view>
		<view class="main" v-on:click.stop>
			<view class="header">
				<image :src="form.showSku.skuImage" mode="aspectFit" class="avt"></image>
				<!-- <view class="price">
					¥
					<text class="num">{{ form.showSku.productPrice }}元/天起</text>
					<text class="old-price" v-if="form.showSku.linePrice">¥{{ form.showSku.linePrice }}</text>
				</view> -->
				<!-- 后续放开 -->
				<view class="price">
					¥
					<text class="num">{{ form.showSku.productPrice }}</text>
					<text class="old-price" v-if="form.showSku.linePrice">¥{{ form.showSku.linePrice }}</text>
				</view>
				<view class="stock">库存：{{ form.showSku.stockNum }}</view>
				<view class="select_spec">{{ selectSpec }}</view>
				<view class="xx-tips">
					<image src="../../../static/icon/xyhf2.png" mode="widthFix"></image>
					<text class="f28 xx-text">0元下单 | 先用后付</text>
				</view>
				<view class="close-btn" @click="closePopup"><text class="icon iconfont icon-guanbi"></text></view>
			</view>
			<view class="address arrow">
				<Myinfo :dis="false"
					:Address="Address" :existAddress="existAddress" @getAddress="getAddress">
				</Myinfo>
			</view>
			<view @click="openUpload" class="f28 d-s-c  arrow" v-if="idAuthStatus != 20 || idFaceStatus != 20">
				<image style="width: 42rpx;height: 42rpx;" class="mr10" src="../../static/icon/rz.png" mode="aspectFill"></image>
				<text>身份信息认证{{idAuthStatus}}{{idFaceStatus}}</text>
			</view>
			<view class="f28 d-s-c IDScan" v-else>
				<image style="width: 42rpx;height: 42rpx;" class="mr10" src="../../static/icon/rz.png" mode="aspectFill"></image>
				<text>身份信息已认证</text>
			</view>
			<view class="body">
				<!--规格-->
				<view>
					<scroll-view scroll-y="true" class="specs" style="max-height: 500rpx;">
						<view v-if="form.specData != null">
							<view class="specs" v-for="(item_attr, attr_index) in form.specData.specAttr" :key="attr_index">
								<view class="specs-hd p-20-0">
									<text class="f26 gray3">{{ item_attr.groupName }}</text>
								</view>
								<view class="specs-list">
									<button
										:class="item.checked ? 'btn-checked' : 'btn-checke'"
										v-for="(item, item_index) in item_attr.specItems"
										:key="item_index"
										@click="selectAttr(attr_index, item_index)"
									>
										{{ item.specValue }}
									</button>
								</view>
							</view>
						</view>
						<view class="specs mt20">
							<view class="specs-hd p-20-0">
								<text class="f26 gray3">支付方式</text>
							</view>
							<view class="specs-list pay-type">
								<view :class="pay_type == 40 ? 'item active' : 'item'" @tap="payTypeFunc(40)">
									<view class="d-s-c">
										<view class="icon-box d-c-c mr10">
											<image src="../../static/icon/zmxx.png" mode="widthFix"></image>
										</view>
										<view class="text-key">
											<text class="key">先用后付</text><text class="zm-rate f22">芝麻分≥550可享</text><text class="f20 introduce">推荐</text>
											<view class="text-tips"><text>0元下单</text>，确认收货再付款</view>
										</view>
									</view>
									<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view>
								</view>
								<!-- <view :class="pay_type == 50 ? 'item active' : 'item'" @tap="payTypeFunc(50)">
									<view class="d-s-c">
										<view class="icon-box d-c-c mr10">
											<image src="../../static/icon/zmxx.png" mode="widthFix"></image>
										</view>
										<view class="text-key">
											<text class="key">先用后付（500元以下）</text>
											<view class="text-tips"><text>0元下单</text>，确认收货再付款</view>
										</view>
									</view>
									<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view>
								</view> -->
								<!-- <view :class="pay_type == 50 ? 'item active' : 'item'" @tap="payTypeFunc(50)">
									<view class="top-tip">最高全免</view>
									<view class="pay-item">
										<view class="icon-box d-c-c mr10">
											<image src="../../static/icon/zmxx.png" mode="widthFix"></image>
										</view>
										<text class="key">芝麻信用 | 免押金</text>
										<view class="tips f24">芝麻分≥550可享</view>
									</view>
								</view> -->
								<view :class="pay_type == 30 ? 'item active' : 'item'" @tap="payTypeFunc(30)">
									<view class="d-s-c">
										<view class="icon-box d-c-c mr10"><span class="icon iconfont icon-zhifubao"></span></view>
										<text class="key">支付宝支付</text>
									</view>
									<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view>
								</view>
								
							</view>
						</view>
					</scroll-view>
					
				</view>
				<!--选择数量-->
				<view class="level-box count_choose">
					<text class="key">数量</text>
					<view class="d-s-c">
						<view class="icon-box minus d-c-c" @click="sub()" :class="{ 'num-wrap': !issub }">
							<text class="icon iconfont icon-jian" style="font-size: 20rpx;color: #333333;"></text>
						</view>
						<view class="text-wrap"><input type="text" v-model="form.showSku.sum"   /></view>
						<view class="icon-box plus d-c-c" :class="{ 'num-wrap': !isadd }" @click="add()">
							<text class="icon iconfont icon-jia" style="font-size: 20rpx;color: #333333;"></text>
						</view>
					</view>
				</view>
			</view>
			<view class="btns">
				<button class="confirm-btn" v-if="hasPhone" @click="confirmFunc(form)">立即下单</button>
				<button class="confirm-btn" v-else open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">立即下单</button>
			</view>
			<!--上传图片-->
			<Upload v-if="isUpload" :show="isUpload" @getImgs="getImgsFunc"></Upload>
			<Verify :isCoupon="isCoupon" @close="closeRiskPop"/>
		</view>
	</view>
</template>

<script>
	import Upload from '@/components/upload/upload.vue';
	import Myinfo from '../../../order/confirm-order/my-info.vue';
	import Verify from './idverify.vue'
	import {
		pay
	} from '@/common/pay.js';
export default {
	components: {
		Myinfo,
		Upload,
		Verify
	},
	data() {
		return {
			isCoupon:false,
			address:null,
			orderId:'',
			options: {},
			pay_type:40,
			/*是否可见*/
			Visible: false,
			/*表单对象*/
			form: {
				detail: {},
				showSku: {
					skuImage: ''
				}
			},
			/*当前商品总库存*/
			stock: 0,
			/*选择提示*/
			selectSpec: '',
			/*是否打开过多规格选择框*/
			isOpenSpec: false,
			type: '',
			hasPhone:uni.getStorageSync('hasPhone'),
			// 是否存在收货地址
			existAddress: false,
			/*默认地址*/
			Address: null,
			isUpload:false,
			isAuth:false,
			idAuthStatus:uni.getStorageSync('idAuthStatus'),
			idFaceStatus:uni.getStorageSync('idFaceStatus'),
		};
	},
	props: ['isPopup', 'productModel'],
	onLoad() {},
	mounted() {},
	computed: {
		/*判断增加数量*/
		isadd: function() {
			return this.form.showSku.sum >= this.stock || this.form.showSku.sum >= this.form.detail.limitNum;
		},

		/*判断减少数量*/
		issub: function() {
			return this.form.showSku.sum <= 1;
		}
	},
	watch: {
		isPopup: function(n, o) {
			// my.getAddress({
			//   success: (res) => {
			// 	  console.log(res,'address res')
			//     // my.alert({
			//     //   title: JSON.stringify(res)
			//     // });
			//   }
			// });
			if (n != o) {
				this.Visible = n;
				if (!this.isOpenSpec) {
					this.form = this.productModel;
					this.isOpenSpec = true;
					this.initShowSku();
				}
				this.form.type = this.productModel.type;
			}
		},
		'form.specData': {
			handler(n, o) {
				let str = '',
					select = '';
				this.isAll = true;
				if (n) {
					for (let i = 0; i < n.specAttr.length; i++) {
						console.log(this.form.productSpecArr);
						console.log('i=' + i);
						if (this.form.productSpecArr[i] == null) {
							this.isAll = false;
							str += n.specAttr[i].groupName + ' ';
						} else {
							n.specAttr[i].specItems.forEach(item => {
								if (this.form.productSpecArr[i] == item.itemId) {
									select += '"' + item.specValue + '" ';
								}
							});
						}
					}
					if (!this.isAll) {
						str = '请选择: ' + str;
					} else {
						select = '已选: ' + select;
					}
				}
				this.selectSpec = this.isAll ? select : str;
			},
			deep: true,
			immediate: true
		}
	},
	methods: {
		closeRiskPop(){
			this.isCoupon = false
		},
		/*打开上传图片*/
		openUpload(index) {
			let self = this;
			self.isCoupon = true
			// my.chooseImage ({
			//   // 可以根据您的业务按需选择使用 ['album'] 或 ['camera'] 或 ['album', 'camera']
			//   sourceType: ['album', 'camera'],
			//   success: function (res) {
			//     console.log (res);
			// 	self.uploadFile(res.tempFilePaths);
			//   },
			//   fail: function (err) {
			//     console.log (err);
			//   },
			// });

			// // this.index = index;
			// console.log(1234)
			// this.isUpload = true;
			// console.log(1234,this.isUpload)
		},
		// /*上传图片*/
		// uploadFile: function(tempList) {
		// 	let self = this;
		// 	let i = 0;
		// 	let img_length=tempList.length;
		// 	let params = {
		// 		token: uni.getStorageSync('token'),
		//         appId: self.getAppId()
		// 	};
		// 	// uni.showLoading({
		// 	//     title: '图片上传中'
		// 	// });
		// 	tempList.forEach(function(filePath, fileKey) {
		// 		uni.uploadFile({
		// 			url: self.websiteUrl + '/api/front/file/upload/image',
		// 			filePath: filePath,
		// 			name: 'iFile',
		// 			formData: params,
		// 			header: {
		// 			  'appId': self.getAppId()
		// 			},
		// 			success: function(res) {
		// 				let result = typeof res.data === 'object' ? res.data : JSON.parse(res.data);
		// 				if (result.code === 1) {
		// 				console.log(result,'result',result.data.filePath)
		// 					self.IDOcr(result.data.filePath)
		// 				}else{
		// 					self.showError(result.msg);
		// 				}
		// 			},
		// 			// complete: function() {
		// 			// 	i++;
		// 			// 	if (img_length === i) {
		// 			// 		uni.hideLoading();
		// 			// 		// 所有文件上传完成
		// 			// 		self.$emit('getImgs',self.imageList);
		// 			// 	}
		// 			// }
		// 		});
		// 	});
			
		// },
		// IDOcr(url){
		// 	console.log(url,'url')
		// 	let self = this
		// 	let result = null
		// 	self._get('user/auth/idOCR',{'idImageUrl':url},function(res){
		// 		// console.log(res,'upload res')
		// 		if(res.code === 1){
		// 			if(!res.data){
		// 				uni.showToast({
		// 					title: '身份证识别失败，请重新上传',
		// 					icon: 'none',
		// 					duration: 3000
		// 				});
		// 			}else{
		// 				result = res.data
		// 				uni.showModal({
		// 					title:'请确定信息是否正确',
		// 					content:`姓名：${res.data.name}身份证号：${res.data.idNumber}`,
		// 					success(res) {
		// 						if(res.confirm){
		// 							self.uploadIDInfo(result,url)
		// 						}else if(res.cancel){
		// 							console.log('cancel')
		// 						}
		// 					}
		// 				})
		// 				// self.uploadIDInfo(res.data)
		// 			}
		// 		}
		// 	})
		// },
		// // 上传身份证信息
		// uploadIDInfo(data,url){
		// 	// /front/user/auth/authID
		// 	let self = this
		// 	self._postBody('user/auth/authID',{...data,idFaceUrl:url},function(res){
		// 		console.log('uploadIDInfo',res)
		// 		if(res.code === 1){
		// 			self.getFaceAuthUrl()
		// 		}
		// 	})
		// },
		// // front/user/auth/getFaceAuthUrl
		// // 获取人脸识别地址
		// getFaceAuthUrl(){
		// 	let self = this
		// 	this._get('user/auth/getFaceAuthUrl',{},function(res){
		// 		console.log(res,'res')
		// 		if(res.code === 1){
		// 			self.toOtherApp(res.data.h5Url)
		// 			// uni.navigateTo({
		// 			// 	url: '/pages/webview/webview?url=' + res.data.h5Url
		// 			// });
		// 		}
		// 	})
		// },
		// toOtherApp(url) {
		// 	let self = this
		// 	console.log(url,self.getAppId(),'url000')
		// 	my.ap.navigateToAlipayPage({
		// 		  path: url
		// 	})
		// },
		/*获取上传的图片*/
		getImgsFunc(e) {
			let self = this;
			// if (e && typeof e != 'undefined') {
			// 	let index = self.index;
			// 	self.tableData[index].imageList = self.tableData[index].imageList.concat(e);
			// }
			console.log(e,'eeeee')
			self.isUpload = false;
		},
		getAddress(data){
			this.Address = data
			console.log(data,'address data')
			// this._postBody('user/address/addZfbAdress', data, function(res) {
			// 	if(res.code === 1){
			// 		this.address = data
			// 	}
			// 	console.log(res,'res zfbAddress')
			// });
		},
		payTypeFunc(n) {
			this.pay_type = n;
		},
		/*初始化*/
		initShowSku() {
			this.form.showSku.skuImage = this.form.detail.image[0].filePath;
			this.form.showSku.productPrice = this.form.detail.productPrice;
			if (this.form.detail.specType == 20) {
				this.form.showSku.productPrice = this.form.detail.productPrice + '-' + this.form.detail.highPrice;
			}
			this.form.showSku.specSkuId = 0;
			this.form.showSku.linePrice = this.form.detail.linePrice;
			this.form.showSku.stockNum = this.form.detail.productStock;
			this.form.showSku.sum = 1;
			this.stock = this.form.detail.productStock;
			if (this.form.plusName == 'seckill') {
				this.form.showSku.productPrice = this.form.plusSku[0].seckillPrice;
				this.form.showSku.linePrice = this.form.plusSku[0].productPrice;
				this.form.showSku.skuImage = this.form.plusSku[0].productSku.imagePath ? this.form.plusSku[0].productSku.imagePath : this.form.detail.image[0].filePath;
				this.form.showSku.stockNum = this.form.plusSku[0].seckillStock;
				this.stock = this.form.plusSku[0].seckillStock;
			}
		},

		/*选择属性*/
		selectAttr(attr_index, item_index) {
			let self = this;
			let items = self.form.specData.specAttr[attr_index].specItems;
			let curItem = items[item_index];
			if (curItem.checked) {
				curItem.checked = false;
				self.form.productSpecArr[attr_index] = null;
			} else {
				for (let i = 0; i < items.length; i++) {
					items[i].checked = false;
				}
				curItem.checked = true;
				self.form.productSpecArr[attr_index] = curItem.itemId;
			}

			for (let i = 0; i < self.form.productSpecArr.length; i++) {
				if (self.form.productSpecArr[i] == null) {
					self.initShowSku();
					return;
				}
			}

			// 更新商品规格信息
			self.updateSpecProduct();
		},

		/*更新商品规格信息*/
		updateSpecProduct() {
			let self = this;
			let specSkuId = self.form.productSpecArr.join('_');
			// 查找skuItem
			let specList = self.form.specData.specList;
			if (self.form.plusSku != null) {
				specList = self.form.plusSku;
			}
			let skuItem = specList.find(val => {
				if (self.form.plusName) {
					return val.productSku.specSkuId == specSkuId;
				} else {
					return val.specSkuId == specSkuId;
				}
			});
			if (!skuItem) {
				self.clock = true;
				self.initShowSku();
				return;
			} else {
				self.clock = false;
			}
			if (self.form.plusName && !skuItem.specForm) {
				skuItem.specForm = skuItem.productSku;
			}
			// 记录product_sku_id
			// 更新商品价格、划线价、库存
			if (typeof skuItem === 'object') {
				/*保存当前规格*/
				console.log(skuItem);
				self.stock = skuItem.specForm.stockNum;
				if (self.form.showSku.sum > self.stock) {
					self.form.showSku.sum = self.stock > 0 ? self.stock : 1;
				}
				self.form.showSku.specSkuId = specSkuId;
				self.form.showSku.productPrice = skuItem.specForm.productPrice;
				self.form.showSku.linePrice = skuItem.specForm.linePrice;
				if (skuItem.specForm.imageId > 0) {
					self.form.showSku.skuImage = skuItem.specForm.imagePath;
				} else {
					self.form.showSku.skuImage = self.form.detail.image[0].filePath;
				}
				self.form.showSku.stockNum = skuItem.specForm.stockNum;
				if (self.form.plusName) {
					self.form.showSku.productPrice = skuItem.productPrice;
					if (self.form.plusName == 'seckill') {
						self.form.showSku.productPrice = skuItem.seckillPrice;
					}
					self.form.showSku.stockNum = skuItem[self.form.plusName + 'Stock'];
					self.form.showSku.linePrice = '';
					self.form.showSku.skuImage = skuItem.specForm.imagePath ? skuItem.specForm.imagePath : self.form.detail.imagePath;
					self.form.showSku.advanceProductId = skuItem.specForm.imagePath ? skuItem.specForm.imagePath : self.form.detail.imagePath;
				}
			}
		},

		/*关闭弹窗*/
		closePopup() {
			this.$emit('close', this.form.specData, null);
		},

		/*确认提交*/
		async confirmFunc() {
			let self = this
			if (this.form.specData != null) {
				for (let i = 0; i < this.form.productSpecArr.length; i++) {
					if (this.form.productSpecArr[i] == null) {
						uni.showToast({
							title: '请选择规格',
							icon: 'none',
							duration: 2000
						});
						return;
					}
				}
			}
			if(!this.Address || !this.Address.addressId){
				uni.showToast({
					title: '请选择收货地址',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if(this.pay_type == 40 || this.pay_type == 50){
				// this._get()
				await this._get('user/auth/getAuthStatus',{},function(res){
					console.log(res,'res====')
					if(res.code === 1){
						if(res.data.idAuthStatus !== 20 || res.data.idFaceStatus !== 20){
							console.log('认证失败')
							self.isAuth = false
							
							return;
						}else{
							self.isAuth = true
						}
					}
				})
				
			}
			
			
			// if(!uni.getStorageSync('hasPhone')){
			// 	this.getPhoneNumber()
			// }
			setTimeout(()=>{
				if(!self.isAuth && (this.pay_type == 40 || this.pay_type == 50)){
					uni.showToast({
						title: '请完成身份信息认证',
						icon: 'none',
						duration: 2000
					});
					return;
				}
				if (this.form.type == 'card') {
					this.addCart();
				} else if (this.form.type == 'order') {
					this.createdOrder();
				} else if (this.form.type == 'deposit') {
					this.createdOrder();
				}
			},500)
		},
		// 获取手机号
		getPhoneNumber(e){
			console.log('getPhoneNumber',e)
			this._post('user/userAli/bindPhoneNumber', {
				sign: e.detail.sign,
				encryptedData:e.detail.encryptedData
				
			}, result => {
				// 记录token userId
				console.log('手机号获取成功')
				if(result.code === 1){
					uni.setStorageSync('hasPhone', true);
					this.confirmFunc()
				}else{
					uni.setStorageSync('hasPhone', false);
				}
				// this.openPopup('order')
				// 执行回调函数
				// uni.navigateBack();
			}, false, () => {
				uni.hideLoading();
			});
			// uni.getPhoneNumber({
			// 	success:res=>{
			// 		console.log(res,'phone success')
			// 	},
			// 	fail:err=>{
			// 		console.log(err,'err phone')
			// 	}
			// })
		},

		/*加入购物车*/
		addCart() {
			let self = this;
			let productId = self.form.detail.productId;
			let totalNum = self.form.showSku.sum;
			//let specSkuId = self.form.showSku.productSkuId;
			let specSkuId = self.form.showSku.specSkuId;
			console.log('specSkuId='+specSkuId);
			if (self.form.detail.specType == 20 && specSkuId == 0) {
				uni.showToast({
					title: '请选择属性',
					icon: 'none',
					duration: 2000
				});
				return false;
			}

			self._post(
				'order/cart/add',
				{
					productId: productId,
					totalNum: totalNum,
					specSkuId: specSkuId
				},
				function(res) {
					uni.showToast({
						title: res.msg,
						duration: 2000
					});
					self.$emit('close', null, res.data);
				}
			);
		},

		/*创建订单*/
		createdOrder() {
			let productId = this.form.detail.productId;
			let productNum = this.form.showSku.sum;
			let productSkuId = this.form.showSku.productSkuId;
			let specSkuId = this.form.showSku.specSkuId;
			let url = 'pages/order/saveOrder?productId=' + productId + '&productNum=' + productNum + '&specSkuId=' + specSkuId + '&orderType=buy';
			if (this.form.type == 'deposit') {
				if (this.form.plusName == 'advance') {
					let skuItem = this.form.detail.advance.sku.find(val => {
						return val.productSku.specSkuId == specSkuId;
					});
					url =
						'pages/order/saveOrder?productId=' +
						productId +
						'&productNum=' +
						productNum +
						'&productSkuId=' +
						specSkuId +
						'&advanceProductSkuId=' +
						skuItem.advanceProductSkuId +
						'&advanceProductId=' +
						skuItem.advanceProductId +
						'&orderType=deposit';
				}
				if (this.form.plusName == 'seckill') {
					let skuItem = this.form.detail.secKill.seckillSku.find(val => {
						return val.productSku.specSkuId == specSkuId;
					});
					console.log(skuItem);
					console.log(specSkuId);
					url =
						'pages/order/saveOrder?seckillProductId=' +
						skuItem.seckillProductId +
						'&productNum=' +
						productNum +
						'&productSkuId=' +
						skuItem.productSku.specSkuId +
						'&seckillProductSkuId=' +
						skuItem.seckillProductSkuId +
						'&orderType=seckill';
				}
			}
			this.SubmitOrder();
			// this.gotoPage(url);
		},
		submitCasher() {
			console.log('submitCasher')
			let self = this;
			self.loading = true;
			uni.showLoading({
				title: '加载中'
			});
			let url = 'user/order/pay';
			// if(self.pay_type==20){
			// 	url = 'plus/package/package/pay';
			// }
			// if(self.pay_type==30){
			// 	url = 'balance/plan/pay';
			// }
			// let use_balance = self.balanceType == true ? 1 : 0;
			// if (self.payPrice == 0) {
			// 	use_balance = 1;
			// }
			let payType=self.pay_type;
			if(payType==10){
				payType=0;
			}
			if(payType==50){
				payType=40;
			}
			let params = {
				orderId: self.orderId,
				paySource: self.getPlatform(),
				payType: payType,
				useBalance: 0,
			}
			self._postBody(url, params,
				function(res) {
					console.log(res,'res');
					self.loading = false;
					uni.hideLoading();
					pay(res, self, self.paySuccess, self.payError);
				})
		},
		paySuccess(result) {
			let self = this;
			if (self.pay_type == 30) {
				self.gotoPage('/pages/user/index/index')
			} else if (self.pay_type == 20) {
				self.gotoPage('/pages/user/index/index')
			} else if (self.pay_type == 40 || self.pay_type == 50) {
				self.gotoPage('/pages/order/myorder')
			} else {
				self.gotoPage('/pages/order/pay-success/pay-success?orderId=' + result.data.orderId, 'reLaunch');
			}
		},
		payError(result) {
			let self = this;
			let url = '/pages/order/myorder';
			// if (self.pay_type == 50 ||self.pay_type == 40 ||self.pay_type == 30 || self.pay_type == 20) {
			// 	uni.navigateBack();
			// } else {
				self.gotoPage('/pages/order/order-detail?orderId=' + result.data.orderId, 'redirect');
			// }
		},
		SubmitOrder() {
			console.log('SubmitOrder')
			let self = this;
			uni.showLoading({
				title: '加载中',
				mask: true
			});
			let params = {
				delivery: 0,
				storeId: self.storeId || 0,
				couponId: 0,
				isUsePoints: '',
				addressId:this.Address.addressId
				// phone: self.lastExtract.phone,
				// linkman: self.lastExtract.linkman,
				// remark: self.remark
			};
		
			// 创建订单-直接下单
			let url = '';
			let productId = this.form.detail.productId;
			let productNum = this.form.showSku.sum;
			let productSkuId = this.form.showSku.productSkuId;
			let specSkuId = this.form.showSku.specSkuId;
			// if (self.options.orderType === 'buy') {
				url = 'order/order/buy';
				params = Object.assign(params, {
					productId: productId,
					productNum: productNum,
					specSkuId: specSkuId
				});
			// }
			//定金
			if (self.options.orderType === 'deposit') {
				url = 'plus.advance.Order/frontBuy';
				params = Object.assign(params, {
					product_id: self.options.product_id,
					product_num: self.options.product_num,
					product_sku_id: self.options.product_sku_id,
					advance_product_sku_id: self.options.advance_product_sku_id,
					advance_product_id: self.options.advance_product_id
				});
			}
			//尾款
			if (self.options.orderType === 'retainage') {
				url = 'plus.advance.Order/buy'
				params = Object.assign(params, {
					order_id: self.options.order_id
				});
			}
			// 创建订单-购物车结算
			if (self.options.orderType === 'cart') {
				url = 'order/order/cart';
				params = Object.assign(params, {
					cartIds: self.options.cartIds || 0
				});
			}
		
			// 创建订单-积分兑换
			if (self.options.orderType === 'points') {
				url = 'plus/points/order/buy';
				params = Object.assign(params, {
					pointProductId: self.options.pointProductId,
					pointProductSkuId: self.options.pointProductSkuId,
					productSkuId: self.options.productSkuId,
					productNum: self.options.productNum
				});
			}
			// 创建订单-限时秒杀
			if (self.options.orderType === 'seckill') {
				url = 'plus/seckill/order/buy';
				params.num = self.options.num;
				params = Object.assign(params, {
					seckillProductId: self.options.seckillProductId,
					productSkuId: self.options.productSkuId,
					seckillProductSkuId: self.options.seckillProductSkuId,
					productNum: self.options.productNum
				});
			}
			// 创建订单-砍价
			if (self.options.orderType === 'bargain') {
				url = 'plus/bargain/order/buy';
				params = Object.assign(params, {
					bargainProductId: self.options.bargainProductId,
					productSkuId: self.options.productSkuId,
					bargainProductSkuId: self.options.bargainProductSkuId,
					bargainTaskId: self.options.bargainTaskId
				});
			}
		
			// 创建订单-限时拼团
			if (self.options.orderType === 'assemble') {
				url = 'plus/assemble/order/buy';
				params = Object.assign(params, {
					assembleProductId: self.options.assembleProductId,
					productSkuId: self.options.productSkuId,
					assembleProductSkuId: self.options.assembleProductSkuId,
					assembleBillId: self.options.assembleBillId,
					productNum: self.options.productNum,
				});
			}
			let callback = function () {
				self._postBody(url, params, function (res) {
					self.orderId = res.data
					let pages = '/pages/order/cashier?orderId=' + res.data;
					if (self.options.orderType == 'deposit') {
						pages = '/pages/order/cashier?orderType=40&orderId=' + res.data;
					}
					self.submitCasher()
					// self.gotoPage(pages, 'reLaunch');
				});
			};
			self.subMessage(self.temlIds, callback);
		},
		/*商品增加*/
		add() {
			if (this.stock <= 0) {
				return;
			}
			if (this.form.showSku.sum >= this.stock) {
				uni.showToast({
					title: '数量超过了库存',
					icon: 'none',
					duration: 2000
				});
				return false;
			}
			if (this.form.detail.limitNum > 0 && this.form.showSku.sum >= this.form.detail.limitNum) {
				uni.showToast({
					title: '数量超过了限购数量',
					icon: 'none',
					duration: 2000
				});
				return false;
			}
			this.form.showSku.sum++;
		},

		/*商品减少*/
		sub() {
			if (this.stock <= 0) {
				return;
			}
			if (this.form.showSku.sum < 2) {
				uni.showToast({
					title: '商品数量至少为1',
					icon: 'none',
					duration: 2000
				});
				return false;
			}
			this.form.showSku.sum--;
		}
	}
};
</script>

<style lang="scss">
.IDScan{
	padding: 20rpx;
}
.arrow{
	position: relative;
	&::after{
		content: '';
		position: absolute;
		right: 20rpx;
		top: 50%;
		transform: translate(0,-50%);
		width: 30rpx;
		height: 25rpx;
		background: url(../../static/icon/arrow.png) center no-repeat;
		background-size: auto 100%;
	}
}
.product-popup {
}
.item {
	min-height: 50rpx;
		line-height: 50rpx;
		padding: 15rpx 30rpx;
		display: flex;
		justify-content: space-between;
		font-size: 26rpx;
	background-color: #FFFFFF;
	// margin-bottom: 28rpx;
	box-shadow: 0rpx 13rpx 27rpx 0rpx rgba(172, 172, 172, 0.09);
	border-bottom: none;
	border-radius: 2rpx;
}
.icon-box{
		width: 40rpx;
		.a-image{
			width: 40rpx;
		}
	}
	.icon-zhifubao{color: #096dd9;}
.product-popup .popup-bg {
	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	background: rgba(0, 0, 0, 0.6);
	z-index: 99;
}

.product-popup .main {
	position: fixed;
	width: 100%;
	bottom: 0;
	min-height: 200rpx;
	// max-height: 1050rpx;
	background-color: #fff;
	transform: translate3d(0, 980rpx, 0);
	transition: transform 0.2s cubic-bezier(0, 0, 0.25, 1);
	// bottom: env(safe-area-inset-bottom);
	z-index: 99;
	border-radius: 12rpx;
}

.product-popup.open .main {
	transform: translate3d(0, 0, 0);
	z-index: 99;
}

.product-popup.close .popup-bg {
	display: none;
}

.product-popup.close .main {
	display: none;
	z-index: -1;
}

.product-popup .header {
	height: 200rpx;
	padding: 40rpx 0 10rpx 250rpx;
	position: relative;
	border-bottom: 1px solid #eeeeee;
}

.product-popup .header .avt {
	position: absolute;
	top: 40rpx;
	left: 30rpx;
	width: 180rpx;
	height: 180rpx;
	border: 2px solid #ffffff;
	background: #ffffff;
	border-radius: 12rpx;
}

.product-popup .header .stock {
	font-size: 26rpx;
	color: #999999;
}

.product-popup .close-btn {
	position: absolute;
	width: 40rpx;
	height: 40rpx;
	top: 40rpx;
	right: 30rpx;
}

.product-popup .price {
	@include font_color('price_color');
	font-size: 24rpx;
}

.product-popup .price .num {
	padding: 0 4rpx;
	font-size: 40rpx;
}

.product-popup .old-price {
	margin-left: 10rpx;
	font-size: 26rpx;
	color: #999999;
	text-decoration: line-through;
}

.product-popup .body {
	padding: 20rpx 30rpx 39rpx 30rpx;
	// max-height: 600rpx;
	overflow-y: auto;
}

.product-popup .level-box {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.product-popup .level-box .key {
	font-size: 24rpx;
	color: #999999;
}

.product-popup .level-box .icon-box {
	width: 48rpx;
	height: 40rpx;
	background: #e0e0e0;
}

.product-popup .num-wrap .iconfont {
	color: #666;
}

.product-popup .num-wrap.no-stock .iconfont {
	color: #cccccc;
}

.product-popup .level-box .text-wrap {
	margin: 0 4rpx;
	height: 60rpx;
	border: none;
	background: #ffffff;
}

.product-popup .level-box .text-wrap input {
	padding: 0 10rpx;
	height: 60rpx;
	line-height: 60rpx;
	width: 80rpx;
	font-size: 32rpx;
	text-align: center;
	vertical-align: super;
}

.specs .specs-list {
	display: flex;
	justify-content: flex-start;
	align-items: center;
	flex-wrap: wrap;
	gap: 20rpx;
	
}

.specs .pay-type{
	display: unset;
}
.specs .specs-list button {
	margin-right: 10rpx;
	margin-bottom: 10rpx;
	font-size: 24rpx;
}

.specs .specs-list button:after,
.product-popup .btns button,
.product-popup .btns button:after {
	height: 88rpx;
	line-height: 88rpx;
	border: 0;
	border-radius: 0;
	margin-bottom: 55rpx;
}

.product-popup .btns .confirm-btn {
	width: 710rpx;
	height: 80rpx;
	@include background_linearmore('cart_right1', 'cart_right2', 'right_deg', 0%, 100%);
	
	border-radius: 40rpx;
	margin: 0 auto;
	margin-bottom: 55rpx;
	color: #ffffff;
	line-height: 80rpx;
	font-size: 32rpx;
	background-color: #FF7A04;
}

.btn-checked {
	border: 1rpx solid #f6220c;
	@include border_color('background_color');
	border-radius: 6px;
	@include font_color('font_color');
	font-size: 26rpx;
	background-color: #ffffff;
	margin: 0 !important;
	margin: 0 !important;
	padding: 0 14px;
}

.btn-checke {
	border: 1rpx solid #d9d9d9;
	border-radius: 6rpx;
	font-size: 26rpx;
	color: #333333;
	background-color: #ffffff;
	margin: 0 !important;
	padding: 0 14px;
}
.item.active .iconfont.icon-xuanze {
	color: #096dd9;
}
.text-tips{
	.tips{
		color: #096dd9;
		@include font_color('font_color');
	}
}
.xx-tips{
	display: flex;
	background-color: rgba(18, 92, 251, 0.2);
	color: rgb(18, 92, 251);
	border-radius: 5rpx;
	    padding: 5rpx 20rpx;
		margin-bottom: 30rpx;
		width: 300rpx;
		margin-top: 10rpx;
	image{
		width: 40rpx;
		margin-right: 20rpx;
	}
}
.introduce{
	color: #ffffff;
	background-color: red;
	    margin-left: 10rpx;
	    border-radius: 20rpx;
	    padding: 5rpx 10rpx;
}
.xx-text{
	line-height: 0.4rem;
}
.zm-rate{
	color: #1677FF;
	border: 1px solid rgba(215,233,255,0.4);
	border-radius: 5rpx;
	padding: 5rpx;
	margin-left: 10rpx;
}
// 暂时修改
// .specs .pay-type{
// 	display: flex;
// 	.item{
// 		width: 47%;
// 		border: 1px solid #ddd;
// 		border-radius: 10rpx;
// 		padding: 30rpx 0;
// 		height: 130rpx;
// 		margin-bottom: 40rpx;
// 		position: relative;
// 		.top-tip{
// 			position: absolute;
// 			top: 0;
// 			right: 0;
// 			background-color: #1677FF;
// 			color: #fff;
// 			font-size: 24rpx;
// 			padding: 0 10rpx;
// 			border-bottom-left-radius: 10rpx;
// 			display: none;
// 		}
// 		&.active{
// 			border-color: #1677FF;
// 			background-color: rgba(22,119,255,0.1);
// 			.top-tip{
// 				display: block;
// 			}
// 		}
// 	}
// }
// .pay-item{
// 	display: flex;
// 	    flex-direction: column;
// 	    align-items: center;
// 	width: 100%;
// 	justify-content: center;
// }
// .tips{
// 	color: #cccccc;
// }
</style>
